<?php
require_once "../libs/ttServer.php";
$tt = new ttServer();

$checkaction = securePOST("checkaction");
$title = securePOST("title");
$content = securePOST2("content");
$author = securePOST("author");
if (strlen($author) <= 0)
{
	$author = "匿名";
}

$ret_id = 0;
if ($checkaction !="" )
{
	if (strlen($title) < 1 || strlen($content) < 20)
	{
		echo  '<script type="text/javascript">alert("请检查标题或内容，不能为空，正文长度不得少于20个字符。");</script>';
	}
	else
	{

		$ret_id = $tt->mblog_add($title, $content, $author);
	}
}


// 检测浏览器类型，针对不同浏览器，下面的代码完全不一样。
$is_mobile = false;
$UA=$_SERVER['HTTP_USER_AGENT'];
if (eregi("mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile|ipod|iphone|android|opera mini|blackberry|palm os|palm|hiptop|avantgo|fennec|plucker|xiino|blazer|elaine|iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile",$UA) == 1 )
{
	// 手机浏览器
	$is_mobile = true;
}

echo '<?xml version="1.0" encoding="utf-8"?>';
?>

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<meta http-equiv="Pragma" content="no-cache"/>
		<meta http-equiv="Cache-Control" content="no-cache"/>
		<meta http-equiv="Expires" content="0"/>
		<title>投递文章 <?php if($is_mobile) echo 'mobile'; ?>  - miniblog - 游味</title>
<style>
.infoTip{
	 background-color:yellow;
	 border-width:1px;
}
</style>
</head>


<?php 
//********************************************************************************************
//**********************************************移动终端**************************************
//********************************************************************************************
	if ($is_mobile)
	{
?>

<body>
	
<?php
if ($checkaction !="" )
{
	if ($ret_id == 0)
	{
			echo '<h1 class="infoTip">文章提交失败，请检查提交的内容。标题不得少于一个字符，正文不得少于20字符</h1>';
	}
	else
	{
			echo sprintf('<h1 class="infoTip">文章提交成功，感谢您的投递。<a href="index.php?id=%d">查看</a></h1>', $ret_id);
	}
}
?>

			
			<h1>新建文章</h1>
			
<?php
if ($checkaction !="" && (strlen($title) < 1 || strlen($content) < 20))
{
?>
		<form id="mblog_article" method="POST" action="add.php">			
			<p>文章标题:</p>
			<input type=text size="60" id="title" name="title" value="<?php echo $title ?>"></input>
			<br/>
			<p>文章正文:</p>
			<div id="myeditor">
				<textarea cols="50" rows="4" id="content" name="content"><?php echo $content ?></textarea>
			</div>
			<p>作者:
			<input type=text size="20" id="author" name="author" value="<?php echo $author ?>"></input>
			</p>
			<div id="submit">
				<input type="hidden" value="chk" name="checkaction"></input>
				<p>
					<input type="submit" value="提交" name="submit"></input>
				</p>
			</div>
		</form>
<?php
}
else 
{
?>
		<form id="mblog_article" method="POST" action="add.php">			
			<p>文章标题:</p>
			<input type=text size="60" id="title" name="title" value=""></input>
			<br/>
			<p>文章正文:</p>
			<div id="myeditor">
				<textarea cols="50" rows="4" id="content" name="content"></textarea>
			</div>
			<p>作者:
			<input type=text size="20" id="author" name="author" value=""></input>
			</p>				
			<div id="submit">
				<input type="hidden" value="chk" name="checkaction"></input>
				<p>
				<input type="submit" value="提交" name="submit"></input>
				</p>
			</div>
		</form>

<?php
}
?>		
			<p></p>
			<div id="footer">游味作品. 版权所有 @2010</div>
			
	</body>








<?php
	}
//********************************************************************************************
//********************************************电脑客户端**************************************
//********************************************************************************************
//********************************************************************************************	
	else	
	{
?>	







<body>
<script src="nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
var mblog_article_editor;

bkLib.onDomLoaded(function() {
	mblog_article_editor = new nicEditor({buttonList : ['bold','italic','underline']}).panelInstance('content');
/*
	new nicEditor({buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','image']}).panelInstance('area4');
*/
});

function submit_article()
{
	//document.getElementById("mblog_article").target="";
	var content= mblog_article_editor.nicInstances[0].getContent();
	var blog_title = document.getElementById("title").value
	if (blog_title.length < 1)
	{
		alert("标题内容太短，请修改后重新提交");
		return true;		
	}
	if (content.length < 20)
	{
		alert("正文内容太短，不足20字符，请修改后重新提交");
		return true;
	}
	document.getElementById("content").value = content;	
	document.getElementById("mblog_article").submit();
}

</script>


<?php
if ($checkaction !="" )
{
	if ($ret_id == 0)
	{
			echo '<h1 class="infoTip">文章提交失败，请检查提交的内容</h1>';
	}
	else
	{
			echo sprintf('<h1 class="infoTip">文章提交成功，感谢您的投递。<a href="index.php?id=%d">查看</a></h1>', $ret_id);
	}
}
?>

			
			<h1>新建文章</h1>
			
<?php
if ($checkaction !="" && (strlen($title) < 1 || strlen($content) < 20))
{
?>
		<form id="mblog_article" method="POST" action="add.php">			
			<p>文章标题:</p>
			<input type=text size="60" id="title" name="title" value="<?php echo $title ?>"></input>
			<br/>
			<p>文章正文:</p>
			<div id="myeditor">
				<textarea cols="50" id="content" name="content" style="height: 400px;"><?php echo $content ?></textarea>
			</div>
			<p>作者:
			<input type=text size="20" id="author" name="author" value="<?php echo $author ?>"></input>
			</p>			
			<div id="submit">
				<input type="hidden" value="chk" name="checkaction"></input>
				<p>
					<a href="#" onclick="submit_article()">提交</a>
				</p>
			</div>
		</form>
<?php
}
else
{
?>
		<form id="mblog_article" method="POST" action="add.php">			
			<p>文章标题:</p>
			<input type=text size="60" id="title" name="title" value=""></input>
			<br/>
			<p>文章正文:</p>
			<div id="myeditor">
				<textarea cols="50" id="content" name="content" style="height: 400px;"></textarea>
			</div>
			<p>作者:
			<input type=text size="20" id="author" name="author" value=""></input>
			</p>			
			<div id="submit">
				<input type="hidden" value="chk" name="checkaction"></input>
				<p>
					<a href="#" onclick="submit_article()">提交</a>
				</p>
			</div>
		</form>

<?php
}
?>		
			<p></p>
			<div id="footer">游味作品. 版权所有 @2010</div>
			<p><a href="index.php">回到首页</a></p>			
	</body>

<?php		
	}
?>
	
</html>
